<layout name="layout" />
<div class="user_main">
    <div class="user_main">
        <div class="content_box">
            <p class="user_main_title">站内短信</p>
            <ul class="note_tit"><li class="active"><a href="#">收件箱</a></li><li><a href="{:U('Message/sendbox')}">发件箱</a></li><li><a href="{:U('Message/send')}">发短信</a></li></ul>
            <p class="note_tit_b"></p>
            <table class="list note">
                <tr>
                    <th class="select">选择</th>
                    <th class="handler">发件人</th>
                    <th class="tit">标题</th>
                </tr>
                <volist name="data.list" id="vo" mod="2">
                    <tr id="message_{$vo.message_id}" <eq name="mod" value="1">class="odd"</eq> overstyle="on">
                    <td class="select"><input name="checkbox" type="checkbox" value="{$vo.message_id}" onclick="checkon(this)" /></td>
                    <td class="handler">{$vo.uname}</td>
                    <td class="tit"> <a href="#" onclick="readMsg({$vo.message_id});">{$vo.title}<if condition="$vo.is_read == 0"><b>(未读)</b></if></td>
                    </tr>
                </volist>
            </table>
            <p class="select">
                <a href="javascript:checkAll(this);">全部选择</a>
                <span>|</span>
                <a href="javascript:unCheckAll(this);">取消选择</a>
            </p>
            <div class="oper">
                <p>{$data.page}</p>
                <button class="field_button" onclick="deleteMessage()">删除</button>
            </div>
        </div>
        <!------------------------------------------------------------------------------------------------------------------------->
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $("tr[overstyle='on']").hover(
        function () {
            $(this).addClass("bg_hover");
        },
        function () {
            $(this).removeClass("bg_hover");
        }
    );
    });
    
    function checkon(o){
        if( o.checked == true ){
            $(o).parents('tr').addClass('bg_on') ;
        }else{
            $(o).parents('tr').removeClass('bg_on') ;
            $(o).parents('tr').removeClass('bg_hover') ;
        }
    }
    
    function unCheckAll(o){
        $('input[name="checkbox"]').removeAttr('checked');
        $('tr[overstyle="on"]').removeClass("bg_on");
    }
    
    function checkAll(o){
        $('input[name="checkbox"]').attr('checked','true');
        $('tr[overstyle="on"]').addClass("bg_on"); 
    }
    
    //获取已选择用户的ID数组
    function getChecked() {
        var ids = new Array();
        $.each($('table input:checked'), function(i, n){
            if($(n).val() > 0)
                ids.push( $(n).val() );
        });
        return ids;
    }
    
    function deleteMessage(ids) {
        var length = 0;
        if(ids) {
            length = 1;    		
        }else {
            ids    = getChecked();
            length = ids.length;
            ids    = ids.toString();
        }
        if(ids=='') {
            alert('请先选择一条信息');
            return ;
        }
        if(confirm('您将删除'+length+'条记录，确定继续？')) {
            $.post("/user/message/delMessage",{ids:ids},function(res){
                if(res=='1') {
                    alert('删除成功');
                    if( length == 1){
                        $('#message_'+ids).remove();
                    }else{
                        removeItem(ids);
                    }
                }else {
                    alert('删除失败');
                }
            });
        }
    }
    function removeItem(ids) {
        ids = ids.split(',');
        for(i = 0; i < ids.length; i++) {
            $('#message_'+ids[i]).remove();
        }
    }
</script>
